import { Controller, Post, Get, UseGuards } from '@nestjs/common';
import { PrivateMessageCleanupService } from './services/private-message-cleanup.service';
import { AuthGuard } from '../../auth/auth.guard';

@Controller('scheduler')
@UseGuards(AuthGuard)
export class SchedulerController {
  constructor(
    private readonly privateMessageCleanupService: PrivateMessageCleanupService,
  ) {}

  /**
   * 手动执行私信消息清理任务
   */
  @Post('cleanup/private-messages')
  async manualCleanupPrivateMessages() {
    await this.privateMessageCleanupService.manualCleanup();
    return {
      success: true,
      message: '私信消息清理任务已手动执行',
      timestamp: new Date().toISOString(),
    };
  }

  /**
   * 获取私信消息清理统计信息
   */
  @Get('cleanup/private-messages/stats')
  async getPrivateMessageCleanupStats() {
    const stats = await this.privateMessageCleanupService.getCleanupStats();
    return {
      success: true,
      data: stats,
      timestamp: new Date().toISOString(),
    };
  }

  /**
   * 获取所有定时任务状态
   */
  @Get('status')
  async getSchedulerStatus() {
    return {
      success: true,
      data: {
        privateMessageCleanup: {
          description: '私信消息清理任务',
          schedule: '每小时执行一次',
          nextExecution: new Date(Date.now() + 60 * 60 * 1000).toISOString(),
          lastExecution: new Date().toISOString(),
        },
      },
      timestamp: new Date().toISOString(),
    };
  }
}
